
using System;

namespace cachier
{


	public class AddCommand : Command
	{
		string[] line;
		
		public AddCommand (string[] line)
		{
			this.line = line;
		}
		
		public bool Process() 
		{
			if (line.Length != 4) return false;
			
			int nominal = int.Parse(line[2]);
			int value = int.Parse(line[3]);
			String currency = line[1].ToUpper();
			
			CurrencyHandler handler;
			if (Storage.getCurrencyMap().ContainsKey(currency)) handler = Storage.getCurrencyMap()[currency];
			else {
				handler = CurrencyHandlerFactory.ParseCurrency(currency);
				Storage.getCurrencyMap().Add(currency, handler);
			}
			
			return handler.Add(nominal, value);
		}
	}
}
